﻿using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using IFWiki.Models;

namespace IFWiki.Utils
{
    public static class Defaults
    {
        public static Article GetArticle(string articleName)
        {
            var article = new Article();
            article.Detail= "**Nothing here yet**";
            article.Name = articleName;
            return article;

        }

        internal static Game GetGame(string name)
        {
            var game = new Game();
            game.AboutGame = "This new game requires a little work.";
            game.GameStyle = "h1 {color:blue;}";
            game.StartingGamePlaceName = "A Town Square";
            game.StartingPlayerJson = "player = {}";
            game.OnPlaceEnterJS =
@"function OnPlaceEnter() {
  //Game specific functions.
  //(Called on entry to every location in the game)      
}";
            game.Name = name;
            return game;
        }

        internal static GamePlace GetGamePlace(string placeName, string gameName)
        {
            var gamePlace = new GamePlace();
            gamePlace.DescriptionMarkdown = "You are standing in a place.";
            gamePlace.PlaceStyle = "h1 {color:blue;}";
            gamePlace.PlaceItemsJson = "place = {}";
            gamePlace.PlaceName = placeName;
            gamePlace.GameName = gameName;
            gamePlace.InitPlaceJS = 
@"function InitPlace() {
  //location specific functions.
  //(Called after the game's place initializer)
}";
            return gamePlace;
        }

        private static IRevisable GetGamePlace(string name)
        {
            name = name.Replace("__game_", "|");
            var names = name.Split('|');
            var placeName = names[0];
            var gameName = names[1];
            return GetGamePlace(placeName, gameName);
        }

        internal static IRevisable GetArticle(Type innerType, string name)
        {
            switch (innerType.ToString())
            {
                case "GamePlace": return GetGamePlace(name); 
                case "Game": return GetGame(name); 
                case "Article": return GetArticle(name); 
                default:
                    return GetArticle(name);
            }
        }
    }
}
